import 'package:flutter/material.dart';
// import 'show_tools.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:flutterapp/config/ImagesConfig.dart';
import 'dart:ui';

class StartPage extends StatefulWidget {
  //启动页
  @override
  _StartPageState createState() => _StartPageState();
}

class _StartPageState extends State<StartPage> {
  bool _islogin = false;
  bool _isFirst = false;
  bool _islastPage = false;
  // List _welcomeList = ["welcome_1.png","welcome_2.png","welcome_3.png"];
  @override
  void initState() {
    super.initState();
    //判断是不是第一次启动
    // _isFirst = SpUtil.getBool("first");
    // _isFirst = true;
    // if(_isFirst){
    //   // String tokenStr = SpUtil.getString("token");
    //   String tokenStr = 'hello world';
    //   _islogin = (tokenStr == null || tokenStr.length == 0) ? false : true;
    //   new Future.delayed(Duration(seconds: 1), () {
    //     //1秒后跳转到其他路由
    //     Navigator.of(context).pushReplacementNamed(_islogin ? "/tabs" : "/login");
    //   });
    // }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        color: Colors.white,
        child: Stack(
          children: [
            Swiper(
              itemBuilder: (BuildContext context, int index) {
                return new Image.asset(
                  welcomeImages[index],
                  fit: BoxFit.fill,
                );
              },
              itemCount: welcomeImages.length,
              pagination: new SwiperPagination(),
              loop: false,
              //autoplay: true,
              // autoplayDelay: 2000,
              onIndexChanged: (index) {
                if (index == welcomeImages.length - 1) {
                  setState(() {
                    _islastPage = true;
                  });
                } else {
                  setState(() {
                    _islastPage = false;
                  });
                }
              },
              onTap: (index) {
                 if (index == welcomeImages.length - 1) {
                   _goWelcome();
                }
              },
            ),
            _islastPage
                ? Align(
                    alignment: Alignment(0, 0.8),
                    child: Container(
                      width: 100,
                      height: 40,
                      // margin: EdgeInsets.only(left: window.physicalSize.width/2-50,bottom: 40,top: window.physicalSize.height - 80,right: window.physicalSize.width/2-50),
                      decoration: BoxDecoration(
                        border: Border.all(color: Colors.white, width: 1),
                      ),
                      child: TextButton(
                        onPressed: () {
                          _goWelcome();
                        },
                        child: Text(
                          "立即体验",
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 15,
                            decoration: TextDecoration.none,
                          ),
                        ),
                      ),
                    ),
                  )
                : Container()
          ],
        ));
  }

  _goWelcome() {
    // SpTools.saveBool("first", true);
    // String tokenStr = SpUtil.getString("token");
    // _islogin = (tokenStr == null || tokenStr.length == 0) ? false : true;
    _islogin = true;
    Navigator.of(context).pushReplacementNamed(_islogin ? "/tabs" : "/login");
  }
}
